#ifndef ENHANCEDHASHTABLE_H
#define ENHANCEDHASHTABLE_H

#include <stdlib.h>
#include "SymEntry.h"
#include "StoreSymEntry.h"
#include "../Scanner-Automat/Token.h"
#include "Key.h"
#include "StoreSymInfo.h"
#include "SymInfo.h"

class SymTable {
private:
	const size_t storeSize;
	SymEntry** table;
	StoreSymEntry symEntryStore;
	StoreSymInfo symInfoStore;
	SymEntry** lastBlock;

	size_t sizeFree;
	size_t size;
	size_t lastBlockSize;
	size_t length;
	size_t overallLength;
	size_t used;

	// checks if table is filled to some extend
	void checkIfExpandNeeded();
	// expands the table
	void expand();
	// helper method for writing pointer to expanded table
	void writeNextBlockPosition(SymEntry** next);

public:
	SymTable(const size_t size);
	virtual ~SymTable();

	// saves a syminfo if it's a new one
	Key insert(char* lexem, TokenType type);
	// returns the syminfo for the key
	SymInfo* lookup(Key key);

	// primitive hash function, just add up char values
	int hashme(char* word) {
		unsigned int result = 0;

		for (int i = 1; i <= word[0]; i++) {
			result += word[i];
		}
		return result;
	}
};

#endif
